Repository navigation
chain: rescan on the client for btcd backends - #1515
Open
eynhaender wants to merge 2 commits into
Open
eynhaender wants to merge 2 commits into
eynhaender wants to merge 2 commits into
Conversation
RPCClient.Rescan issued the btcd rescan command, which rpcclient marks as deprecated in favor of rescanblocks. Perform the rescan on the client instead: load the addresses and outpoints with loadtxfilter, walk the main chain from the start block with getheaders, and match each batch of blocks with rescanblocks. As with the rescan command, the start block is included and matching transactions are delivered as relevant transactions. A progress notification follows each batch. At the best block, the addresses and the unspent outpoints, including outputs found by the scan, are registered with notifyreceived and notifyspent, and blocks connected in the meantime are scanned before the rescan finishes. A start block outside the main chain, or a batch that does not link to the last scanned block, fails the rescan. This allows btcd-compatible servers that do not implement the deprecated rescan command, such as libbitcoin-server, to serve as a chain backend.
Add TestRPCClientRescanReorgServer, which runs the client-side rescan against a btcd miner and changes the chain before a chosen call of the rescan: invalidateblock followed by a fork with more work, or new blocks. Each case builds about 2600 blocks above the best block with three payments to the watched address, so that the rescan takes two getheaders batches. A rescan either finishes at the best block and notifies each payment mined in the main chain once, in its block, or fails. Transactions notified before a failure must be in the blocks they were notified in. The cases cover a reorganization of the start block before the first scan, of rescanned blocks, of a fetched batch before its scan, ahead of the rescanned blocks, and of the last block at the best block, and new blocks at the best block. With RESCAN_REORG_SERVER the rescan runs against another btcd-compatible server instead, which follows the miner over p2p.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RPCClient.Rescanused the btcdrescancommand, which rpcclient marks as deprecated in favor ofrescanblocks. The rescan now runs on the client, so btcd-compatible servers withoutrescan, such as libbitcoin-server, can serve as a chain backend, including for lnd's btcd backend.Related: lightningnetwork/lnd#11583 removes lnd's own use of
rescanin the btcd chain notifier.Change Description
loadtxfilterloads the addresses and outpoints.getheaderswalks the main chain from the start block in batches of 2000 headers. A batch that does not link to the last scanned block fails the rescan withErrRescanReorg.rescanblocksmatches each batch. Matches are delivered as relevant transactions, followed by a progress notification per batch.notifyreceivedandnotifyspent. Blocks connected in the meantime are scanned before the rescan finishes.As with
rescan, the start block is included. A rescan without addresses or outpoints finishes at the best block without scanning.TestRPCClientRescanReorgServerruns the rescan against a btcd harness miner and changes the chain before a chosen call of the rescan: the start block, rescanned blocks or a fetched batch reorganized, a reorganization ahead of the scan, the last block reorganized or new blocks at the best block. The rescan must either finish with each main chain payment notified once, in its block, or fail without notifying a transaction outside its block.Steps to Test
go test -race ./chain/ -run TestRPCClientRescanNotes
rescan, the wallet's rescan handler keeps the failed batch; this PR does not change that.rescanis sent, and all 1372 wallet rescans finish.